#include <stdio.h>
#include <stdlib.h>

#include "parallel_sort.hpp"
#include "flash_sort.h"

template<typename T>
bool check_sort_result(T *data1, T *data2, int size) {
  for (int i = 0; i < size; ++i) {
    if (data1[i] != data2[i]) return false;
  }
  return true;
}

void parallel_sort_test() {
  const int size = 10000000;
  float *data = new float[size];
  float *data2 = new float[size];
  for (int i = 0; i < size; ++i) {
    data[i] = rand();
  }
  memcpy(data2, data, size * sizeof(int));

  clock_t t0 = clock();
  std::sort(data, data + size);
  clock_t t1 = clock();
  //parallel_sort(data2, size);
  int count = 0;
  flashsort(data2, size, CLASS_SIZE, &count);
  clock_t t2 = clock();
  if (check_sort_result(data2, data, size)) {
    printf("serial time: %f\n", (t1 - t0) / 1000.0);
    printf("parallel time: %f\n", (t2 - t1) / 1000.0);
  } else {
    printf("parallel sort error!\n");
  }
  delete[] data;
  delete[] data2;
}

int main() {
  parallel_sort_test();
}